const app = getApp();
Component({
  properties: {},
  data: {
    active: 0,
    hide: false,
    color: "#999999",
    selectedColor: "#fff",
    list: [
      {
        "pagePath": "pages/index/index",
        "text": "名片",
        "iconPath": "/pages/images/index.png",
        "selectedIconPath": "/pages/images/index_actove.png",
        "hump": false
      },
      {
        "pagePath": "pages/my/my",
        "text": "我的",
        "iconPath": "/pages/images/ma_acriv.png",
        "selectedIconPath": "/pages/images/ma2.png",
        "hump": false
      }
    ]
  },
  attached() { },
  methods: {
    // onChange(event) {
    //   this.setData({
    //     active: event.currentTarget.dataset.value
    //   });
    //   wx.switchTab({
    //     url: this.data.list[event.currentTarget.dataset.value].pagePath.startsWith('/') ?
    //       this.data.list[event.currentTarget.dataset.value].pagePath : `/${this.data.list[event.currentTarget.dataset.value].pagePath}`,
    //   });
    // },

    // init() {
    //   const page = getCurrentPages().pop();
    //   const route = page ? page.route.split('?')[0] : '';
    //   const active = this.data.list.findIndex(
    //     (item) =>
    //       (item.pagePath.startsWith('/') ? item.pagePath.substr(1) : item.pagePath) ===
    //       `${route}`,
    //   );
    //   console.log(active)
    //   this.setData({
    //     active: active
    //   });
    // },

    switchTab(e) {
      const data = e.currentTarget.dataset;
      console.log(data);
      //const url = data.path;
      wx.switchTab({
        url: this.data.list[data.index].pagePath.startsWith('/') ?
          this.data.list[data.index].pagePath : `/${this.data.list[data.index].pagePath}`,
      })
      this.setData({
        active: data.index
      })
    },
    /**
     * 显示tabbar
     * @param e
     */
    showTab(e) {
      this.setData({
        hide: false
      }, function () {
        console.log("showTab执行完毕");
      });
    },
    /**
     * 隐藏tabbar
     * @param e
     */
    hideTab(e) {
      this.setData({
        hide: true
      }, function () {
        console.log("hideTab执行完毕");
      });
    },
  }
})